#pragma once

#include "map/griddefines.h"
#include "system/grid/girdloader.h"
#include "map/cell.h"

class ObjectWorldLoader;

using GridLoaderType = game::system::grid::GridLoader<battle::object::Player, WorldTypeMapContainer, GridTypeMapContainer>;

class Map;
struct Cell;
class ObjectGridLoader
{
    friend class ObjectWorldLoader;

public:
    ObjectGridLoader(NGridType& grid, Map* map, const Cell& cell)
        : i_cell(cell), i_grid(grid), i_map(map), i_gameObjects(0), i_creatures(0), i_corpses(0)
    {
    }

    void Load(GridType& grid);
#if 0
    void Visit(GameObjectMapType& m);
    void Visit(CreatureMapType& m);
    void Visit(CorpseMapType&) {}

    void Visit(DynamicObjectMapType&) {}
#endif
    void LoadN(void);

private:
    Cell i_cell;
    NGridType& i_grid;
    Map* i_map;
    unsigned int i_gameObjects;
    unsigned int i_creatures;
    unsigned int i_corpses;
};

class ObjectGridUnloader
{
public:
    ObjectGridUnloader(NGridType& grid) : i_grid(grid) {}

    void MoveToRespawnN();
    void UnloadN()
    {
        GridLoaderType loader;
        for (unsigned int x = 0; x < MAX_NUMBER_OF_CELLS; ++x)
        {
            for (unsigned int y = 0; y < MAX_NUMBER_OF_CELLS; ++y)
            {
                loader.Unload(i_grid(x, y), *this);
            }
        }
    }

    void Unload(GridType& grid);
#if 0
    template<class T> void Visit(GridRefManager<T>& m);
#endif
private:
    NGridType& i_grid;
};

class ObjectGridStoper
{
public:
    ObjectGridStoper(NGridType& grid) : i_grid(grid) {}

    void StopN()
    {
        GridLoaderType loader;
        for (unsigned int x = 0; x < MAX_NUMBER_OF_CELLS; ++x)
        {
            for (unsigned int y = 0; y < MAX_NUMBER_OF_CELLS; ++y)
            {
                loader.Stop(i_grid(x, y), *this);
            }
        }
    }

    void Stop(GridType& grid);
#if 0
    void Visit(CreatureMapType& m);
#endif
#if 0
    template<class NONACTIVE> void Visit(GridRefManager<NONACTIVE>&) {}
#endif
private:
    NGridType& i_grid;
};
